<template> 
    <div class="app-container">
        <el-card class="filter-container" shadow="never">
            <div>
                <i class="el-icon-search"></i>
                <span>筛选搜索</span>
                <el-button style="float: right" @click="searchPmsSkuChangedetailsList()" type="primary" size="small">查询结果</el-button>
            </div>
            <div style="margin-top: 15px">
                <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
                    <el-form-item label="商品名称:">
                        <el-input style="width: 203px" v-model="listQuery.productName" placeholder="商品名称"></el-input>
                    </el-form-item>
                    <el-form-item label="国际码:">
                        <el-input style="width: 203px" v-model="listQuery.productSn" placeholder="国际码"></el-input>
                    </el-form-item>
                    <el-form-item label="自编码:">
                        <el-input style="width: 203px" v-model="listQuery.shopProductCode" placeholder="自编码"></el-input>
                    </el-form-item>
                    <el-form-item label="品牌:">
                        <el-input style="width: 203px" v-model="listQuery.brandName" placeholder="品牌"></el-input>
                    </el-form-item>
                    <el-form-item label="分类名称:">
                        <el-input style="width: 203px" v-model="listQuery.productCategoryName" placeholder="分类名称"></el-input>
                    </el-form-item>
                    <el-form-item label="操作员昵称:">
                        <el-input style="width: 203px" v-model="listQuery.nickName" placeholder="国际码"></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
        <div class="table-container">
            <el-table ref="pmsSkuChangedetailsTable" :data="list" style="width: 100%" @selection-change="handleSelectionChange" v-loading="listLoading" border height="70vh">
                <el-table-column type="selection" align="center"></el-table-column>
                <el-table-column v-for="(item,index) in tabelHead" :prop="item.prop" :label="item.label" min-width="50px"></el-table-column>
                <el-table-column v-for="(item,index) in summaryHead" :prop="item.prop" :label="item.label":formatter="formatterData" :min-width="item.width"></el-table-column>
            </el-table>
        </div>
        <div class="batch-operate-container">

        </div>
        <div class="pagination-container">
            <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    layout="total, sizes,prev, pager, next,jumper"
                    :page-size="listQuery.pageSize"
                    :page-sizes="[5,10,15]"
                    :current-page.sync="listQuery.pageNum"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    //将$都替换为$
    import {findPmsBacklogByPage} from '@/api/prm/pmsSkuChangedetails'
    import {formatDate} from '@/utils/date';
    import {fetchList} from '@/api/prm/pmsDict'
    

    export default {
        name: 'findPmsSkuChangeSummaryByPage',
        data() {
            return {
                operates: [],
                operateType: null,
                listQuery: {
                    keyword: null,
                    pageNum: 1,
                    pageSize: 10
                },
                list: null,
                total: null,
                listLoading: true,
                multipleSelection: [],
                tabelHead:[
                    {prop:"productName",label:"商品名称"},
                    {prop:"productSn",label:"国际码"},
                    {prop:"shopProductCode",label:"自编码"},
                    {prop:"unit",label:"单位"},
                    {prop:"shopSize",label:"规格"},
                    {prop:"brandName",label:"品牌名称"},
                    {prop:"productCategoryName",label:"分类名称"},
                    {prop:"storeName",label:"店铺名称"},
                ],
                summaryHead:[],
                dict:[]
            }
        },
        created() {
            this.getDict();
            this.getList();
        },
        filters: {
            formatCreateTime(time) {
                let date = new Date(time);
                return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
            },
            formatStatus(value) {
                if (value === 1) {
                    return '未开始';
                } else if (value === 2) {
                    return '活动中';
                } else if (value === 3) {
                    return '已结束';
                } else if (value === 4) {
                    return '已失效';
                }
            },
        },
        methods: {
            getDict(){
                let head = [];
                fetchList({dicType:"出入库明细单据类型"}).then(response => {
                    let data = response.data.records;
                    this.dict = data;
                    data.find(item=>{
                        head.push({prop:"createTime"+item.code,label:"最后"+item.value+"时间",width:"160px"});
                        head.push({prop:"num"+item.code,label:"最后"+item.value+"数量",width:"50px"});
                    })
                    
                })
                this.summaryHead = Object.assign(head)
            },
            getList() {
                this.listLoading = true;
                findPmsBacklogByPage(this.listQuery).then(response => {
                    this.listLoading = false;
                    this.list = response.data.records;
                    this.total = response.data.total;
                    this.totalPage = response.data.pages;
                    this.pageSize = response.data.size;
                })
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleSizeChange(val) {
                this.listQuery.pageNum = 1;
                this.listQuery.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.listQuery.pageNum = val;
                this.getList();
            },
            searchPmsSkuChangedetailsList() {
                this.listQuery.pageNum = 1;
                this.getList();
            },
            formatterData(row, column, cellValue, index){
                let returnValue = "";
                if(cellValue != null && cellValue != ""){
                    if(column.property.indexOf("createTime")!=-1){
                        let date = new Date(cellValue);
                        returnValue = formatDate(date, 'yyyy-MM-dd hh:mm:ss')
                    }else{
                        returnValue = cellValue;
                    }
                }
                return returnValue;
            }
        }
    }
</script>